<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction {
   function __construct() {
       parent::__construct();
       if(isset($_SESSION['uid'])&&  intval($_SESSION['uid'])>0){
           $this->redirect("book/index/");
       }else{
           
       }
       
       
   }
    public function index(){
        $this->redirect("login");
        
        
    }
    
    public function login(){
        $this->display();
    }
    
    public function reg(){
        $this->display();
    }
    public function dolog(){
        if(isset($_POST['username'])&&$_POST['username']!=''
                &&isset($_POST['password'])&&$_POST['password']!=''
                &&isset($_POST['code'])&&$_POST['code']!=''
                &&$_POST['code']==$_SESSION['checkCode']){
            
            $where=Array(
                "member_name"=>$_POST['username'],
                "password"=>  md5($_POST['member_password']),
                "member_status"=>1
            );
            $member=D("member");
            $select=$member->where($where)->find();
            if($select){
                $_SESSION['uid']=$select['mid'];
                $this->redirect("book/index/");
            }else{
                $this->error("用户名或密码错误");
            }
            
            
            
        }else{
            $this->error("数据错误");
        }
    }
    public function doreg(){
        if(isset($_POST['username'])&&$_POST['username']!=''
                &&isset($_POST['password'])&&$_POST['password']!=''
                &&isset($_POST['password1'])&&$_POST['password1']!=''
                &&$_POST['password1']==$_POST['password']
                &&isset($_POST['code'])&&$_POST['code']!=''
                &&$_POST['code']==$_SESSION['checkCode']){
            
            $insert_arr=Array(
                "member_name"=>$_POST['username'],
                "member_password"=>md5($_POST['password']),
                "sid"=>0,
                "member_creattime"=>time(),
                "member_thislogintime"=>time(),
                "member_lastlogintime"=>time(),
                "member_lastloginip"=>$_SERVER['REMOTE_ADDR'],
                "member_thisloginip"=>$_SERVER['REMOTE_ADDR'],
                "member_status"=>1,
            );
            $member=D("member");
            $insert=$member->data($insert_arr)->add();
            if($insert!==false){
                $_SESSION['uid']=$member->getLastInsID();
                $this->redirect("/book/index/");
            }else{
                //echo $member->getLastSql();
                $this->error("注册失败");
            }
            
            
            
        }else{
            $this->error("数据错误");
        }
    }
    
}